@extends('admin.layouts.wap_simple')
@section('title', '小程序信息详情')

@section('content')
<script type="text/javascript" src="/assets/admin/js/dev/miniapp.setting.875451.js?v={{ time() }}"></script>

<a class="mini-detial-header" href="{{ url('/admin/miniapps/miniapp_publish',['appid'=>$miniapp->appid]) }}">
    <img src="{{ $basicInfo['head_image_info']['head_image_url'] }}">
    <div class="info">
        <h3>{{ empty($basicInfo['nickname']) ? "未设置" : $basicInfo['nickname'] }}</h3>
        <h5>
            @if(!$qualification_verify)
            <font class="m-bg-warning">待认证</font>
            @else
            <font class="m-bg-success">已支付</font>
            @endif
            {{ $basicInfo['appid'] }}
        </h5>
        <div class="signature">{{ empty($basicInfo["signature_info"]["signature"]) ? "暂未配置小程序简介" : $basicInfo["signature_info"]["signature"] }}</div>
    </div>
</a>

@if(!$qualification_verify)
    <div class="mini-detial-info">
        <div class="header"><b>微信小程序认证</b></div>
        <ul>
            <li>
                <span>认证状态：</span>
                <font class="text-danger">未认证</font>
            </li>
            <li>
                <span>名称认证：</span>
                @if($basicInfo["wx_verify_info"]["naming_verify"])
                <font class="text-success">已认证</font>
                @else
                <font class="text-danger">未认证</font>
                @endif
            </li>
            <li>
                <span>支付状态：</span>
                @if($miniapp->pay_status == 2)
                <font class="text-success">已支付</font>
                @else
                <font class="text-danger">未支付</font>
                @endif
            </li>
        </ul>
        @if($miniapp->pay_status == 1)
        <div class="m-btn m-btn-block m-btn-primary m-mt-1" onclick='mviewNotification("warning","订单支付说明","点击开始实名认证后会将扣除订单并不支持退款，请确认是否认证？","确认并开始","取消",{"appid":"{{ $basicInfo['appid'] }}","type":"verify"})'>立即前往实名认证</div>
        @else
        <div class="m-btn m-btn-block m-btn-primary m-mt-1" onclick='mviewNotification("warning","认证说明","支付订单后，点击确认即开始认证操作，请确认是否开始认证？","确认并开始","取消",{"appid":"{{ $miniapp->appid }}","type":"verify_mini"})'>立即前往实名认证</div>
        @endif
    </div>
@else
    <div class="mini-detial-info">
        <div class="header"><b>微信小程序认证</b></div>
        <ul>
            <li>
                <span>认证状态：</span>
                <font class="text-success">已认证</font>
            </li>
            <li>
                <span>名称认证：</span>
                @if($basicInfo["wx_verify_info"]["naming_verify"])
                <font class="text-success">已认证</font>
                @else
                <font class="text-danger">未认证</font>
                @endif
            </li>
            <li>
                <span>是否需要年审：</span>
                @if($basicInfo["wx_verify_info"]["annual_review"])
                <font class="text-warning">需年审</font>
                @else
                <font class="text-success">无须年审</font>
                @endif
            </li>
            <li>
                <span>年审开始时间：</span>
                <font>{{ date("Y-m-d H:i:s",$basicInfo["wx_verify_info"]["annual_review_begin_time"]) }}</font>
            </li>
            <li>
                <span>年审截止时间：</span>
                <font>{{ date("Y-m-d H:i:s",$basicInfo["wx_verify_info"]["annual_review_end_time"]) }}</font>
            </li>
        </ul>
    </div>

    <div class="mini-detial-info">
        <div class="header"><b>小程序备案</b></div>
        <ul>
            <li>
                <span>备案状态</span>
                <font>{{ $icpStatus[$entranceInfo["status"]] }}</font>
            </li>
            <li>
                <span>注销备案</span>
                @if($entranceInfo["is_canceling"])
                <font class="m-text-warning">正在注销</font>
                @else
                <font>未注销</font>
                @endif
            </li>
            <li>
                <span>是否可备案</span>
                @if($entranceInfo["available"] == 1)
                <font class="m-text-success">可以</font>
                @else
                <font class="m-text-danger">不可以</font>
                @endif
            </li>
            @if(in_array($entranceInfo["status"],[3,5]))
            <li style="display:flex;flex-direction:column;">
                <span>审核驳回原因</span>
                @foreach($entranceInfo["audit_data"] as $auditData)
                <div class="re-reason">
                    <p class="m-text-danger">不通过字段:{{ $auditData["key_name"] }}</p>
                    <p><span>原因:</span>{{ $auditData["error"] }}</p>
                    <p><span>修改建议:</span>{{ $auditData["suggest"] }}</p>
                </div>
                @endforeach
            </li>
            @endif
        </ul>
    </div>

    <div class="mini-detial-info">
        <div class="header"><b>小程序上架</b></div>
        <ul>
            <li>
                <span>小程序状态</span>
                @if($miniapp->status == 1)
                <font class="text text-success">已上架</font>
                @elseif($miniapp->status == 2 || $miniapp->status == 3)
                <font class="text">试用预授权</font>
                @elseif($miniapp->status == 4)
                <font class="text">等待认证</font>
                @elseif($miniapp->status == 5)
                <font class="text">未提交审核</font>
                @elseif($miniapp->status == 6)
                <font class="text text-warning">小程序审核中</font>
                @elseif($miniapp->status == 7)
                <font class="text text-danger">小程序未通过</font>
                @else
                <font class="text text-primary">待发布小程序</font>
                @endif
            </li>
            <li>
                <span>小程序版本</span>
                <font>{{ empty($miniapp->version) ? "未上架" : $miniapp->version }}</font>
            </li>

            @if(in_array($miniapp->status,[2,3,4]))
                <a href="{{ url('/admin/miniapps/fast_register_crop_weapp_status',['id'=>$miniapp->id]) }}" class="mini-detial-btn m-mr-1">前往认证</a>
            @elseif($miniapp->status == 1)
            @elseif($miniapp->status == 5)
                <a href="{{ url('/admin/miniapps/miniapp_publish',['appid'=>$miniapp->appid]) }}" class="mini-detial-btn m-mr-1">前往上架微信小程序</a>
            @elseif($miniapp->status == 6)
                <a href="javascript:;" class="mini-detial-btn m-btn-danger"  onclick='mviewNotification("warning","撤回审核提醒","撤回审核后审核需重新排队,请确认是否继续撤回？","确定撤回","取消",{"appid":"{{ $miniapp->appid }}","type":"miniapp_audit_cancel"})'>撤回小程序审核</a>
            @elseif($miniapp->status == 7)
                <a href="{{ url('/admin/miniapps/miniapp_publish',['appid'=>$miniapp->appid]) }}" class="mini-detial-btn m-mr-1">重新提交审核</a>
            @else
                <a href="{{ url('/admin/miniapps/weapp_audit',['appid'=>$miniapp->appid]) }}" class="mini-detial-btn m-mr-1">前往发布小程序</a>
            @endif
            <input type="hidden" id="appid" value="{{ $miniapp->appid }}">
        </ul>
    </div>
    <div class="mini-detial-info">
        <div class="header"><b>更多小程序信息</b></div>
        <ul>
            <li>
                <span>小程序账号类型：</span>
                @if($basicInfo["account_type"] == 1)
                <font>订阅号</font>
                @elseif($basicInfo["account_type"] == 2)
                <font>服务号</font>
                @else
                <font>小程序</font>
                @endif
            </li>
            <li>
                <span>主体类型：</span>
                @if($basicInfo["principal_type"] == 0)
                <font>个人</font>
                @elseif($basicInfo["principal_type"] == 1)
                <font>企业</font>
                @elseif($basicInfo["principal_type"] == 2)
                <font>媒体</font>
                @elseif($basicInfo["principal_type"] == 3)
                <font>政府</font>
                @else
                <font>其他组织</font>
                @endif
            </li>
            <li>
                <span>主体名称：</span>
                <font>{{ $basicInfo["principal_name"] }}</font>
            </li>
            <li>
                <span>实名认证状态：</span>
                @if($basicInfo["realname_status"] == 1)
                <font>实名验证成功</font>
                @elseif($basicInfo["realname_status"] == 2)
                <font>实名验证中</font>
                @else
                <font>实名验证失败</font>
                @endif
            </li>
            <li>
                <span>认证类型：</span>
                @if($basicInfo["customer_type"] == 1)
                <font>企业</font>
                @elseif($basicInfo["customer_type"] == 2)
                <font>企业媒体</font>
                @elseif($basicInfo["customer_type"] == 3)
                <font>政府</font>
                @elseif($basicInfo["customer_type"] == 4)
                <font>非盈利组织</font>
                @elseif($basicInfo["customer_type"] == 5)
                <font>民营非企业</font>
                @elseif($basicInfo["customer_type"] == 6)
                <font>盈利组织</font>
                @elseif($basicInfo["customer_type"] == 8)
                <font>社会团体</font>
                @elseif($basicInfo["customer_type"] == 9)
                <font>事业媒体</font>
                @elseif($basicInfo["customer_type"] == 11)
                <font>事业单位</font>
                @elseif($basicInfo["customer_type"] == 12)
                <font>个体工商户</font>
                @elseif($basicInfo["customer_type"] == 14)
                <font>海外企业</font>
                @else
                <font>未认证</font>
                @endif
            </li>
            <li style="display:flex;align-items: center">
                <span>APPID：</span>
                <font style="flex: 1;text-align: right" id="miniappid">{{$basicInfo['appid']}}</font>
                <i style="padding: 0 8px;font-style: normal;background-color: #000;color: #fff;font-size: 12px;height: 22px;line-height: 22px;margin-left: 10px;" onclick="copyText(4,'小程序appid')">复制</i>
            </li>
            <li style="display:flex;align-items: center">
                <span>原始id：</span>
                <font style="flex: 1;text-align: right" id="minioriid">{{$miniapp->original_id}}</font>
                <i style="padding: 0 8px;font-style: normal;background-color: #000;color: #fff;font-size: 12px;height: 22px;line-height: 22px;margin-left: 10px;" onclick="copyText(5,'小程序原始id')">复制</i>
            </li>
            <li>
                <span>创建时间：</span>
                <font>{{ $miniapp->created_at }}</font>
            </li>
            {{-- <li id="is-bind-email" style="display: none">
                <span>邮箱</span>
                <font id="is-email"></font>
            </li> --}}
            <li style="display:flex;align-items: center">
                <span>邮箱：</span>
                <font id="email-name" style="flex: 1;text-align: right;overflow: hidden;text-overflow: ellipsis;white-space: nowrap">3usdifufg@163.com</font>
                <span style="padding: 0 8px;font-style: normal;background-color: #000;color: #fff;font-size: 12px;height: 22px;line-height: 22px;margin-left: 10px;" onclick="copyText(1,'邮箱')" id="copy-mail">复制</span>
                <span style="padding: 0 8px;font-style: normal;background-color: #ffc505;color: #fff;font-size: 12px;height: 22px;line-height: 22px;margin-left: 10px;" id="change-mail" onclick="changeMail()">换一个</span>
                <span style="padding: 0 8px;font-style: normal;background-color: #27ff0f;color: #fff;font-size: 12px;height: 22px;line-height: 22px;margin-left: 10px;" id="bind-mail" onclick="bindMail()">绑定</span>
            </li>
            <li style="display:flex;align-items: center">
                <span>邮箱密码：</span>
                <font id="email-pwd" style="flex: 1;text-align: right">aajjhg6677</font>
                <i style="padding: 0 8px;font-style: normal;background-color: #000;color: #fff;font-size: 12px;height: 22px;line-height: 22px;margin-left: 10px;" onclick="copyText(2,'邮箱密码')" id="copy-pwd">复制</i>
            </li>
            <li style="display:flex;align-items: center">   
                <span>小程序密码</span>
                <font style="flex: 1;text-align: right">wxx098765</font>
                <i style="padding: 0 8px;font-style: normal;background-color: #000;color: #fff;font-size: 12px;height: 22px;line-height: 22px;margin-left: 10px;" onclick="copyText(3,'小程序密码')" id="copy-minipwd">复制</i>
            </li>
            <li>
                <span>备注</span>
                <a onclick="remarkshow()" href="javascript:;">更新备注</a>
            </li>
            <font color="#999999" id="remark-text">{{ empty($miniapp->remark) ? '暂未备注' : $miniapp->remark }}</font>
        </ul>
        <div class="m-form-item">
            <a href="https://mp.weixin.qq.com/wxopen/componentrebindadmin?appid={{ $miniapp->appid }}&component_appid={{ $component_appid }}&redirect_uri=https://bab.moreqifu.cn/admin/miniapps/component_rebind_admin_back/{{ $miniapp->appid }}" class="m-form-btn m-mr-1">换绑小程序管理员</a>
            <a class="m-form-btn m-btn-danger m-mr-1" onclick='mviewNotification("info","删除小程序提醒","删除小程序后将会从小程序列表移除,如想要取消授权请前往小程序后台主动取消授权！","确认删除","取消",{"type":"mini_delete","id":"{{ $miniapp->id }}"});'>删除小程序</a>
        </div>
    </div>
    <div class="model-mask" id="remark-mask" style="display: none;">
        <div class="model-remark">
            <div class="remark-con">
                <font>备注：</font>
                <textarea rows="3" id="remark-t" placeholder="请输入备注内容" value=""></textarea>
                <div>
                    <span onclick="cancellation()">取消</span>
                    <span onclick="submitRemark('{{ $miniapp->appid }}')">确认</span>
                </div>
            </div>
        </div>
    </div>
@endif
<style type="text/css">
    .model-mask{
        width: 100vw;
        height: 100vh;
        position: fixed;
        background-color: rgba(0, 0, 0, .5);
        top: 0;
        left: 0;
    }
    .model-remark{
        width: 380px;
        position: absolute;
        background-color: #ffffff;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        border-radius: 3px;
    }
    .remark-con{
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        padding: 10px 15px;
        max-height: 500px;
        overflow-y: auto;
    }
    .remark-con > font{
        height: 25px;
        line-height: 25px;
        margin: 0 0 10px;
        font-size: 16px;
        color: #666666;
    }
    .remark-con > textarea{
        padding: 5px 10px;
        line-height: 20px;
        border: 1px solid #cccccc;
        border-radius: 3px;
    }
    font{
        word-break: break-all
    }
    textarea:focus {
        outline: none;
        border: 1px solid #91a7ff!important;
        border-radius: 3px;
    }
    .remark-con > div{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        height: 30px;
        margin-top: 15px;
    }
    .remark-con > div > span{
        margin: 0 0 0 20px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        background-color: #007bff;
        color: #ffffff;
        font-size: 14px;
        border-radius: 3px;
        cursor: pointer;
        padding: 0 10px;
    }
    .remark-con > div > span:first-child{
        background-color:#74788d!important
    }

    .remark-con > li{
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 30px;
        line-height: 30px;
        margin: 0 0 10px;
        font-size: 14px;
        color: #666666;
    }
    .re-reason{
        margin-bottom: 15px;
    }
    .re-reason p{
        color: #999999;
        line-height: 25px;
    }
    .re-reason span{
        color: #666666;
        margin-right: 10px;
    }
</style>
<script type="text/javascript">
    var mail_data={}; 
    var mail_num; 
    function remarkshow(){
        var remark_a = $("#remark-text").text().replace('更新备注','');
        var remark_val = remark_a == '暂未备注' ? '' : remark_a;
        $("#remark-t").val(remark_val);
        $("#remark-mask").show();
    }
    function cancellation() {
        $(".model-mask").hide();
    }
    function submitRemark(appid) {
        let remark_te = $("#remark-t").val();
        if(remark_te.length > 255){
            mviewToastr("error","最长不能超过255字！");
            return;
        }
        $.ajax({
            "url": "/admin/miniapps/mini_remark",
            "type": "GET",
            "data": {"appid":appid,"remark":remark_te},
            success: function(res){
                console.log(res);
                mviewToastr(res.status,res.msg); 
                if(res.status == 'success'){
                    $("#remark-text").text(remark_te);
                }
                setTimeout(()=>{
                    $(".model-mask").hide();
                },500)
            },
            error: function(err){
                mviewToastr("error","请求失败,请稍后重试！");
            }
        });
    }
    $(document).ready(function () {
        $.ajax({
            "url": "/admin/miniapps/miniapp_get_mail",
            "type": "GET",
            "data": {"appid":$("#appid").val()},
            success: function(res){
                if(res.status =='success'){
                    mail_data = res.data.albindmail;
                    mail_num = res.data.num;
                    if(mail_num > 2 ){
                        $("#change-mail").hide();
                    }
                    $("#email-name").text(mail_data.email); 
                    $("#email-pwd").text(mail_data.password);
                    if(res.msg == '已绑定邮箱' ){
                        $("#copy-pwd").hide();
                        $("#copy-minipwd").hide();
                        $("#copy-mail").hide();
                    }
                }else{
                    $("#email-name").text('暂无邮箱，请联系管理员'); 
                    $("#email-pwd").text('暂无邮箱');
                    $("#change-mail").hide();
                    $("#copy-pwd").hide();
                    $("#copy-minipwd").hide();
                    $("#copy-mail").hide();
                    $("#bind-mail").hide(); 
                }
            },
            error: function(err){
                // mviewToastr("error","请求失败,请稍后重试！");
            }
        });
    });

    function changeMail() {
        $.ajax({
            "url": "/admin/miniapps/miniapp_change_mail",
            "type": "GET",
            "data": {"appid":$("#appid").val(),id:mail_data.id},
            success: function(res){
                if(res.status =='success'){
                    mviewToastr("success",res.msg);
                    mail_data = res.data.albindmail;
                    mail_num = res.data.num;
                    if(mail_num > 2 ){
                        $("#change-mail").hide();
                    }
                    $("#email-name").text(mail_data.email); 
                    $("#email-pwd").text(mail_data.password);
                }else{
                    mviewToastr("error",res.msg);
                }
            },
            error: function(err){
                mviewToastr("error","请求失败,请稍后重试！");
            }
        });
    }

    function bindMail() {
        $.ajax({
            "url": "/admin/miniapps/miniapp_bind_mail",
            "type": "GET",
            "data": {"appid":$("#appid").val(),id:mail_data.id}, 
            success: function(res){
                if(res.status =='success'){
                    mviewToastr("success",res.msg);
                    $("#change-mail").hide();
                    $("#copy-pwd").hide();
                    $("#copy-minipwd").hide();
                    $("#copy-mail").hide();
                    $("#bind-mail").hide();
                }else{
                    mviewToastr("error",res.msg);
                }
            }
        })
    }

    function copyText(text,tip="") {
        if(text == 1){
            text = $("#email-name").text();
        }else if(text == 2){
            text = $("#email-pwd").text();
        }else if(text == 3){
            text = 'wxx098765';
        }else if(text == 4){
            text = $("#miniappid").text();
        }else if(text == 5){
            text = $("#minioriid").text();
        }
        const textarea = document.createElement('textarea');
        textarea.value = text;
        document.body.appendChild(textarea);
        textarea.select();
        document.execCommand('copy');
        document.body.removeChild(textarea);
        mviewToastr("success",tip+'复制成功!');
    }
    

</script>
@endsection
